package tech.cyhk.cloud.demo.order.interceptor;

import feign.InvocationContext;
import feign.Response;
import feign.ResponseInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
 * @author swd
 * @date 2025/1/21
 */
@Slf4j
@Component
public class FeignResponseTokenInterceptor implements ResponseInterceptor {

    @Override
    public Object intercept(InvocationContext invocationContext, Chain chain) throws Exception {

        Response response = invocationContext.response();
        if (Objects.nonNull(response) && response.headers().containsKey("x-token-res")) {
            for (String s : response.headers().get("x-token-res")) {
                log.info("{}", s);
            }
        }


        return chain.next(invocationContext);
    }
}
